home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.onyx.net!claymoor
- From: Adam.Morris@octacon.co.uk (Adam Morris)
- Newsgroups: comp.lang.c++
- Subject: Re: A beginners valiant effort.
- Date: Mon, 26 Feb 96 19:24:58 GMT
- Organization: Octacon Ltd
- Message-ID: <4gsft7$jhc@mulgave.octacon.co.uk>
- References: <4g81kr$mrs@soap.news.pipex.net> <4gcvq9$8ro@nntpd2.cxo.dec.com>
- NNTP-Posting-Host: claymoor.onyx.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4gcvq9$8ro@nntpd2.cxo.dec.com>,
- Brian Hibbert <b_hibbert@csc32.enet.dec.com> wrote:
- >chris.neale@ooh.conqueror.co.uk (Chris Neale) wrote:
- >>but the IF statement falls through - like a switch statement. Try it
- [deletions]
- >You program is not falling through the if statement to the else clause.
- >The problem is with the strings that you have built and the storage space
- >allocated for them. You are using an output operator that expects a
- >character pointer to point to a null terminated string and you are
- >passing it a pointer to a string that is not terminated. What happens is
-
- Forgive me if I am wrong, but I always thought that constant strings were null
- terminated.... "test" is expanded by the compiler to 't','e','s','t','\0'
- Thus explicit null termination of the strings in the program is not required.
- the problem (as I see it) is that the array that the strings are being stored
- in is not large enough to include the null terminating character, so that when
- the character constants are assigned to the arrays, the terminating character
- is chopped off.
-
- Just increasing the size of the two arrays by one each should be enough to do
- it.
-
- Adam.
-